package com.example.controller;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.entity.PsInspectiontaskDetail;
import com.example.service.impl.PsInspectiontaskDetailServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 伍彦端
 * @since 2024-04-24
 */
@CrossOrigin(origins="*")
@ResponseBody
@RestController
@RequestMapping("/psinspectiontaskdetail")
public class PsInspectiontaskDetailController {
    @Resource
    private PsInspectiontaskDetailServiceImpl psInspectiontaskDetailService;

    @RequestMapping("/show")
    public Object show(Integer tid, Integer nowPage){
        System.out.println(tid);
        if (tid==null){
            tid=104;
        }

        PsInspectiontaskDetail psInspectiontaskDetail = new PsInspectiontaskDetail();
        psInspectiontaskDetail.setTaskid(tid.longValue());
        if (nowPage==null){
            nowPage=1;
        }
        nowPage=(nowPage-1)*2;
        return psInspectiontaskDetailService.show(nowPage,2,psInspectiontaskDetail);
    }


    @Transactional
    @RequestMapping("/update")
    public Object update(int[] idArr, int[] queIdArr){
        boolean flagOne=false;
        UpdateWrapper updateWrapper=new UpdateWrapper();
        for (int i=0; i<idArr.length; i++){
            updateWrapper.eq("id",idArr[i]);
            updateWrapper.set("aa",queIdArr[i]);
            boolean flag = psInspectiontaskDetailService.update(updateWrapper);
            if (flag==false){
                flagOne=false;
                throw new RuntimeException("修改异常！");
            }else {
                flagOne=true;
            }
        }
        return flagOne;
    }

}
